import mod_idgen

class Thing:
    def __init__(self,prototype):
        self.ID = mod_idgen.theIDGen.getNextID()
        self.prototype = prototype
        self.HP = prototype.maxHP
        self.location = None
        self.calcResistanceMap()
        
    def takeDamage(self,damage,type):
        actualDamage = int(round(damage * self.currentResistanceMap.get(type,1.0))) # Resistance defaults to 1
        self.setHP(self.HP - actualDamage)
        
    def calcResistanceMap(self):
        self.currentResistanceMap = self.prototype.resistanceMap
        
    def setHP(self,newHP):
        if newHP > self.maxHP:
            newHP = self.maxHP
        self.HP = newHP
        if newHP <= 0:
            self.die()